#!/usr/bin/env python
# -*- coding: UTF-8 -*-
"""
@Project ：pytest_allure_pytest-html_study 
@File    ：10_动态生成标题.py
@IDE     ：PyCharm 
@Author  ：XiaoDengYa
@Date    ：2021/6/3/003 16:31 
"""


# 参数化无标题的栗子

import allure
import pytest


# @pytest.fixture()
# def login(request):
#     """登录"""
#     param = request.param
#     print(f"账号是：{param['username']}，密码是：{param['pwd']}")
#     # 返回
#     return {"code": 0, "msg": "success!"}
#
# datas = [
#     {"username": "name1", "pwd": "pwd1"},
#     {"username": "name2", "pwd": "pwd2"},
#     {"username": "name3", "pwd": "pwd3"}
# ]
#
# @allure.story('登录功能')
# @pytest.mark.parametrize('login', datas, indirect=True)
# def test_login1(login):
#     """
#     登录测试用例1
#     """
#     assert login['code'] == 0


# 参数化有标题写死的栗子
# 将上面的测试代码添加一个 @allure.title 就可以了
'''
@pytest.fixture()
def login(request):
    param = request.param
    print("测试数据未：{}".format(param))
    return param

datas = [
    {"code":0},
    {"code":0},
    {"code":0},
]


@allure.story('登录功能')
@allure.title('登录测试用例2')
@pytest.mark.parametrize('login', datas, indirect=True)
def test_login2(login):
    """
    登录测试用例2
    """
    assert login['code'] == 0
'''

'''
# 参数化使用 ids 的栗子
import allure
import pytest


@pytest.fixture()
def login(request):
    """登录"""
    param = request.param
    print(f"账号是：{param['username']}，密码是：{param['pwd']}")
    # 返回
    return {"code": 0, "msg": "success!"}

datas = [
    {"username": "name1", "pwd": "pwd1"},
    {"username": "name2", "pwd": "pwd2"},
    {"username": "name3", "pwd": "pwd3"}
]

ids = [
    "username is name1,pwd is pwd1",
    "username is name2,pwd is pwd2",
    "username is name3,pwd is pwd3"
]

@allure.story('登录功能')
@pytest.mark.parametrize('login', datas, ids=ids, indirect=True)
def test_login1(login):
    """
    登录测试用例1
    """
    assert login['code'] == 0
'''

# 参数化动态生成标题的栗子
'''
import allure
import pytest


@pytest.fixture()
def login(request):
    """登录"""
    param = request.param
    print(f"账号是：{param['username']}，密码是：{param['pwd']}")
    # 返回
    return {"code": 0, "msg": "success!"}


datas = [
    {"username": "name1", "pwd": "pwd1"},
    {"username": "name2", "pwd": "pwd2"},
    {"username": "name3", "pwd": "pwd3"}
]

data2 = [
    ("name1", "123456"),
    ("name2", "123456"),
    ("name3", "123456")
]


@allure.story('分别传值')
@allure.title('登录测试用例2-账号是：{username}-密码是：{pwd}')
@pytest.mark.parametrize('username,pwd', data2)
def test_login1(username, pwd):
    """
    登录测试用例1
    """
    print(username, pwd)


@allure.story('字典参数化')
@allure.title('登录测试用例2-{dict}')
@pytest.mark.parametrize('dict', datas)
def test_login2(dict):
    """
    登录测试用例1
    """
    print(dict['username'], dict['pwd'])


@allure.story('传值进fixture')
@allure.title('登录测试用例2{login}')
@pytest.mark.parametrize('login', datas, indirect=True)
def test_login3(login):
    """
    登录测试用例2
    """
    assert login['code'] == 0
'''
'''
# 参数化动态生成标题最优方案的栗子
import allure
import pytest

data = [
    ("name1", "123456", "name1 登录成功"),
    ("name2", "123456", "name2 登录失败"),
    ("name3", "123456", "name3 登录成功")
]


@allure.story('分别传值')
@allure.title('登录测试用例-{title}')
@pytest.mark.parametrize('username,pwd,title', data)
def test_login1(username, pwd, title):
    """
    登录测试用例1
    """
    print(username, pwd)
'''
